window.onload = function () {

    //权限处理begin
    var permissionsArray = $(".onejiba").attr("arr").split(",");
    $(".onejiba").children().not(".amiba,.jinshi101,.twojibafazhan,.twojibazhuangbei,.twojibazhongxin,.twojibazongbu,.twojibaqita").css({
        "display": "none"
    });
    if ($(".jinshi101").css("display") == "none") {
        alert("jinshi101")
        for (var i = 0; i < permissionsArray.length; i++) {
            alert(permissionsArray[i]);
            switch (permissionsArray[i]) {
                case "101":
                    $(".onejiba .jinshi101").css({
                        "display": "block"
                    })
                    break;
                case "102":
                    $(".onejiba .twojibafazhan").css({
                        "display": "block"
                    })
                    break;
                case "103":
                    $(".onejiba .twojibazhuangbei").css({
                        "display": "block"
                    })
                    break;
                case "104":
                    $(".onejiba .twojibazhongxin").css({
                        "display": "block"
                    })
                    break;
                case "105":
                    $(".onejiba .twojibazongbu").css({
                        "display": "block"
                    })
                    break;
                case "134":
                    $(".onejiba .twojibaqita").css({
                        "display": "block"
                    })
                    break;
                case "137":
                    $(".onejiba .threejibaqita").css({
                        "display": "block"
                    })
                    $(".onejiba .threejibaqita li").css({
                        "display": "none"
                    })
                    break;
                case "138":
                    $(".onejiba .threejibaqita").css({
                        "display": "block"
                    })
                    $(".onejiba .threejibaqita li").css({
                        "display": "none"
                    })
                    break;
                case "115":
                    $(".onejiba .threejibazhuangbei").css({
                        "display": "block"
                    })
                    $(".onejiba .threejibazhuangbei li").css({
                        "display": "none"
                    })
                    break;
                case "122":
                    $(".onejiba .threejibazhuangbei").css({
                        "display": "block"
                    })
                    $(".onejiba .threejibazhuangbei li").css({
                        "display": "none"
                    })
                    break;
                case "109":
                    $(".onejiba .threejibaqita").css({
                        "display": "block"
                    })
                    $(".onejiba .threejibaqita li").css({
                        "display": "none"
                    })
                    break;
                case "123":
                    $(".onejiba .threejibazhongxin").css({
                        "display": "block"
                    })
                    $(".onejiba .threejibazhongxin li").css({
                        "display": "none"
                    })
                    $('a[index="+permissionsArray[i]+"]').parent().css({
                        "display": "block"
                    })
                    break;
                case "106":
                    $(".onejiba .threejibazhongxin").css({
                        "display": "block"
                    })
                    $(".onejiba .threejibazhongxin li").css({
                        "display": "none"
                    })
                    alert($('a[index="+permissionsArray[i]+"]').parent()[0].tagName)
                    $('a[index="+permissionsArray[i]+"]').parent().css("display", "block")
                    break;
                default:
                    break;
            }
        }

        function forfun(arr) {
            for (var j = 0; j < arr.length; j++) {
                if (permissionsArray.indexOf(arr[j]) != -1) {
                    $('a[index="+arr[j]+"]').parent().css("display", "block")
                }
            }
        }

        (function zhongxin() {
            var departmemtn = []
            var zxArr = ["106", "119", "120", "121", "123"];
            var fzArr = ["107", "108", "110", "111", "112", "113", "114", "116", "117", "118", "124", "125", "126"];
            var zbArr = ["109", "115", "122"];
            var zbguanliArr = ["127", "128", "129", "130", "131", "132", "133", "134", "135"];
            var qitaArr = ["137", "138"];
            departmemtn.push(zxArr);
            departmemtn.push(fzArr);
            departmemtn.push(zbArr);
            departmemtn.push(zbguanliArr);
            departmemtn.push(qitaArr);
            for (var i = 0; i < departmemtn.length; i++) {
                forfun(departmemtn[i])
            }
        })()
    } else {
        $(".onejiba").children().not(".amiba").css({
            "display": "none"
        })
    }
    $(".amiba").click(function () {
        var hasClass = $(".amiba a").prev().hasClass("DropDownimg");
        if (!hasClass) {//进行展开
            // alert(1)
            if ($(".jinshi101").css("display") == "none") {
                for (var i = 0; i < permissionsArray.length; i++) {
                    switch (permissionsArray[i]) {
                        case "101":
                            $(".onejiba .jinshi101").css({
                                "display": "block"
                            })
                            break;
                        case "102":
                            $(".onejiba .twojibafazhan").css({
                                "display": "block"
                            })
                            break;
                        case "103":
                            $(".onejiba .twojibazhuangbei").css({
                                "display": "block"
                            })
                            break;
                        case "104":
                            $(".onejiba .twojibazhongxin").css({
                                "display": "block"
                            })
                            break;
                        case "105":
                            $(".onejiba .twojibazongbu").css({
                                "display": "block"
                            })
                            break;
                        case "134":
                            $(".onejiba .twojibaqita").css({
                                "display": "block"
                            })
                            break;
                        case "106":
                            $(".onejiba .threejibazhongxin").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibazhongxin li").css({
                                "display": "none"
                            })
                            break;
                        case "107":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "108":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "109":
                            $(".onejiba .threejibaqita").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibaqita li").css({
                                "display": "none"
                            })
                            break;
                        case "111":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "112":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "113":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "114":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "115":
                            $(".onejiba .threejibazhuangbei").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibazhuangbei li").css({
                                "display": "none"
                            })
                            break;
                        case "116":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "117":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "118":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "119":
                            $(".onejiba .threejibazhongxin").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibazhongxin li").css({
                                "display": "none"
                            })
                            break;
                        case "120":
                            $(".onejiba .threejibazhongxin").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibazhuangbei li").css({
                                "display": "none"
                            })
                            break;
                        case "121":
                            $(".onejiba .threejibazhongxin").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibazhuangbei li").css({
                                "display": "none"
                            })
                            break;
                        case "122":
                            $(".onejiba .threejibazhuangbei").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibazhuangbei li").css({
                                "display": "none"
                            })
                            break;
                        case "123":
                            $(".onejiba .threejibazhongxin").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibazhongxin li").css({
                                "display": "none"
                            })
                            break;
                        case "124":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "125":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "126":
                            $(".onejiba .threejibafazhan").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibafazhan li").css({
                                "display": "none"
                            })
                            break;
                        case "127":
                            $(".onejiba .threejibazongbu").css({
                                "display": "block"
                            })
                            $(".onejiba .threejibazongbu li").css({
                                "display": "none"
                            })
                            break;
                        default:
                            break;
                    }
                }

                function forfun(arr) {
                    for (var j = 0; j < arr.length; j++) {
                        if (permissionsArray.indexOf(arr[j]) != -1) {
                            console.log(arr[j])

                            $('a[index=' + arr[j] + ']').parent().css("display", "block")
                        }
                    }
                }

                (function zhongxin() {
                    var departmemtn = []
                    var zxArr = ["106", "119", "120", "121", "123"];
                    var fzArr = ["107", "108", "110", "111", "112", "113", "114", "116", "117", "118", "124", "125", "126"];
                    var zbArr = ["109", "115", "122"];
                    var zbguanliArr = ["127", "128", "129", "130", "131", "132", "133", "134", "135"];
                    var qitaArr = ["137", "138"];
                    departmemtn.push(zxArr);
                    departmemtn.push(fzArr);
                    departmemtn.push(zbArr);
                    departmemtn.push(zbguanliArr);
                    departmemtn.push(qitaArr);
                    for (var k = 0; k < departmemtn.length; k++) {
                        forfun(departmemtn[k])
                    }
                })()
            } else {
                $(".onejiba").children().not(".amiba").css({
                    "display": "none"
                })
            }
            $(".amiba a").prev().replaceWith('<img class="DropDownimg" src="../images/file1.ico" alt=""/>');
        } else {
            $(".onejiba").children().not(".amiba").css({
                "display": "none"
            })
            $(".amiba a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
            $(".jinshi101 a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
            $(".twojibafazhan a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
            $(".twojibazhuangbei a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
            $(".twojibazhongxin a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
            $(".twojibazongbu a").prev().replaceWith('<img class="DropDownimg" src="../images/file2.ico" alt=""/>');
            $(".twojibaqita a").prev().replaceWith('<img class="DropDownimg" src="../images/file2.ico" alt=""/>');
        }
    })
    //权限处理end
    $(".jinshi101 li").click(function () {
        var hasClass = $(".jinshi101 a").prev().hasClass("DropDownimg");
        if (!hasClass) {
            $(".jinshi101 a").prev().replaceWith('<img class="DropDownimg" src="../images/file2.ico" alt=""/>');
        } else {
            $(".jinshi101 a").prev().replaceWith('<img class="Dropimg" src="../images/file1.ico" alt=""/>');
        }
        if (permissionsArray.indexOf("102") != -1) {
            alert(permissionsArray)
            $(".twojibafazhan").toggle(function () {
                if (!hasClass) {
                } else {
                    $(".twojibafazhan a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
                }
            });
        }
        if (permissionsArray.indexOf("103") != -1) {
            $(".twojibazhuangbei").toggle(function () {
                if (!hasClass) {
                } else {
                    $(".twojibazhuangbei a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
                }
            });

        }
        if (permissionsArray.indexOf("104") != -1) {
            $(".twojibazhongxin").toggle(function () {
                if (!hasClass) {
                } else {
                    $(".twojibazhongxin a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
                }
            });
        }
        if (permissionsArray.indexOf("105") != -1) {
            $(".twojibazongbu").toggle(function () {
                if (!hasClass) {
                } else {
                    $(".twojibazongbu a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
                }
            });
        }
        if (permissionsArray.indexOf("134") != -1) {
            $(".twojibaqita").toggle(function () {
                if (!hasClass) {
                } else {
                    $(".twojibaqita a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
                }
            });
        }
        if (permissionsArray.indexOf("101") != -1 && permissionsArray.indexOf("102") != -1 && permissionsArray.indexOf("103") != -1 && permissionsArray.indexOf("104") != -1 && permissionsArray.indexOf("105") != -1 && permissionsArray.indexOf("136") != -1) {
            $(".twojibazhongxin,.twojibazhuangbei,.twojibafazhan,.twojibazongbu,.twojibaqita").toggle();
        }

        if (permissionsArray.indexOf("101") != -1 && permissionsArray.indexOf("102") == -1 && permissionsArray.indexOf("103") == -1 && permissionsArray.indexOf("104") == -1 && permissionsArray.indexOf("105") == -1 && permissionsArray.indexOf("136") == -1) {
            $(".twojibazhongxin,.twojibazhuangbei,.twojibafazhan,.twojibazongbu,.twojibaqita").toggle();
        }
        $(".threejibafazhan,.threejibazhuangbei,.threejibazhongxin,.threejibazongbu,.threejibaqita").css("display", "none");
    })
    $(".twojibafazhan li").click(function () {
        var hasClass = $(".twojibafazhan a").prev().hasClass("DropDownimg");
        if (!hasClass) {
            $(".twojibafazhan a").prev().replaceWith('<img class="DropDownimg" src="../images/file1.ico" alt=""/>');
        } else {
            $(".twojibafazhan a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
        }
        $(".threejibafazhan").toggle("normal");
    })
    $(".twojibazhuangbei li").click(function () {
        var hasClass = $(".twojibazhuangbei a").prev().hasClass("DropDownimg");
        if (!hasClass) {
            $(".twojibazhuangbei a").prev().replaceWith('<img class="DropDownimg" src="../images/file1.ico" alt=""/>');
        } else {
            $(".twojibazhuangbei a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
        }
        $(".threejibazhuangbei").toggle("normal");
    })
    $(".twojibazhongxin li").click(function () {
        var hasClass = $(".twojibazhongxin a").prev().hasClass("DropDownimg");
        if (!hasClass) {
            $(".twojibazhongxin a").prev().replaceWith('<img class="DropDownimg" src="../images/file1.ico" alt=""/>');
        } else {
            $(".twojibazhongxin a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
        }
        $(".threejibazhongxin").toggle("normal");
    })
    $(".twojibazongbu li").click(function () {
        var hasClass = $(".twojibazongbu a").prev().hasClass("DropDownimg");
        if (!hasClass) {
            $(".twojibazongbu a").prev().replaceWith('<img class="DropDownimg" src="../images/file1.ico" alt=""/>');
        } else {
            $(".twojibazongbu a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
        }
        $(".threejibazongbu").toggle("normal");
    })
    $(".twojibaqita li").click(function () {
        var hasClass = $(".twojibaqita a").prev().hasClass("DropDownimg");
        if (!hasClass) {
            $(".twojibaqita a").prev().replaceWith('<img class="DropDownimg" src="../images/file1.ico" alt=""/>');
        } else {
            $(".twojibaqita a").prev().replaceWith('<img class="Dropimg" src="../images/file2.ico" alt=""/>');
        }
        $(".threejibaqita").toggle("normal");
    })
//    下拉按钮的展示

// 展示数据表

}

//筛选年月和状态触发函数
function getFyDhListByFyXqCode() {
    var year = $("#fyXq").val();
    var month = $("#fyHx").val();
    var state = $("#fyStatus").val();
    var deparentNum = storage.get("deparentNum").deparentNum;
    getTheTable(deparentNum)
}

//侧边栏点击效果begin
function getTheTable(arg, pageNumber) {
    var state = 0;//状态
    var deparentNum = $(arg).children("a").attr("index");
    if (!$(arg).children("a").attr("index")) {
        deparentNum = arg;
    }
    storage.set("deparentNum", {deparentNum: deparentNum});
    deparentNum = storage.get("deparentNum").deparentNum;
    console.log('deparentNum', deparentNum);
    var pageNumber1 = pageNumber == undefined ? 1 : pageNumber;
    var year = $("#fyXq").val();
    var month = $("#fyHx").val();
    state = $("#fyStatus").val();
    var url = "http://localhost:3000/deparentNum/?" + "deparentNum=" + deparentNum + "&pageNumber=" + pageNumber1 + "&year=" + year + "&month=" + month + "&state=" + state;
    $.ajax({
        type: 'GET',
        url: url,
        success: function (res) {
            console.log("看是否登录", res.resultRes);
            if (res.resultRes != undefined) {
                if (res.resultRes.indexOf("重新") != -1) {
                    location.reload();
                    return;
                }
            }
            //渲染表格begin
            $(".focus_item_data tbody").empty();
            for (var i in res.result) {
                $(".focus_item_data tbody").append("<tr></tr>")
                for (var j in res.result[i]) {
                    if (j == "create_time") {
                        var dateee = new Date(res.result[i][j]).toJSON();
                        var date = new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td>' + date + '</td>');
                    } else {
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td>' + res.result[i][j] + '</td>');
                    }
                }
                if (res.result[i]["state"] === 1) {//状态为抓取的时候
                    if (res.result[i]["grade"] != 3) {
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td colspan="5"><a href="javascript:;" style="color: red;">汇总中</a></td>');
                    } else {
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td colspan="5"><a href="javascript:;" style="color: red;">抓取中</a></td>');
                    }
                } else if (res.result[i]["state"] === 0) {//状态为抓取完成的时候

                    if (res.result[i]["grade"] != 3) {//不是3级巴的时候全部不可以进入修改
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="viewtable(this)"><a href="javascript:;"></a></td>');
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="unlockauthority(this)"><a href="javascript:;" style="color:red;"></a></td>');
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="download(this)"><a href="javascript:;"></a></td>');
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="devaretable(this)"><a href="javascript:;"></a></td>');
                        $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="heckdata(this)"><a href="javascript:;"></a></td>');
                    } else {
                        //3级巴的时候判断这个用户是否有修改的权限,有的可进入修改
                        if (res.Modify_authority === 1) {
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="viewtable(this)"><a href="javascript:;"></a></td>');
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="editortable(this)"><a href="javascript:;"></a></td>');
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="download(this)"><a href="javascript:;"></a></td>');
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="devaretable(this)"><a href="javascript:;"></a></td>');
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="heckdata(this)"><a href="javascript:;"></a></td>');
                        } else {
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="viewtable(this)"><a href="javascript:;"></a></td>');
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="alert(\'请联系管理员解锁后修改\')"><a href="javascript:;" style="color:red;"></a></td>');
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="download(this)"><a href="javascript:;"></a></td>');
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="devaretable(this)"><a href="javascript:;"></a></td>');
                            $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="heckdata(this)"><a href="javascript:;"></a></td>');
                        }
                    }
                } else if (res.result[i]["state"] === 2) {//状态为锁定的时候
                    $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="viewtable(this)"><a href="javascript:;"></a></td>');
                    $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="unlockauthority(this)"><a href="javascript:;" style="color:red;"></a></td>');
                    $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="download(this)"><a href="javascript:;"></a></td>');
                    $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="devaretable(this)"><a href="javascript:;"></a></td>');
                    $('.focus_item_data tbody tr:eq(' + i + ')').append('<td onclick="heckdata(this)"><a href="javascript:;"></a></td>');
                }
            }
            pagingfun(res.pageMax, res.pageNumber, deparentNum);
            // pagingfun=null;
            // 渲染表格end
            var grade = $("tbody tr:eq(0) td:eq(7)").text();
            if (grade == 3 || grade == "") {
                $(".ui_input_btn02").eq(0).addClass("ui_input_btn01");
                $(".ui_input_btn02").eq(1).removeClass("ui_input_btn01")
            } else {
                $(".ui_input_btn02").eq(1).addClass("ui_input_btn01");
                $(".ui_input_btn02").eq(0).removeClass("ui_input_btn01")
            }
        }
    });
}

// 分页begin
function pagingfun(pageMax, pageNumber, deparentNum) {
    var curPage = pageNumber;
    var last = pageMax;
    $("#totalPage").val(last)
    var page = Math.ceil(curPage / 10);
    //调用绘制分页样式函数
    draw(page, curPage);
    //绑定点击页码事件
    $(document).off("click", ".pagination li a");
    $(document).on("click", ".pagination li a", function () {
        var str = $(this).html();
        if (typeof Number(str) !== "string") {
            getTheTable(deparentNum, Number(str))
        }
        if (!isNaN(str)) {
            //移除之前的active
            $(".pagination li a").removeClass("active");
            $(this).attr("class", "active");
            $("#currentPage").val(str);
        }
    });
    //绑定下一页点击事件
    $(document).off("click", "#nextPage");
    $(document).on("click", "#nextPage", function () {
        var num = $(".active").html();
        var curPage = $("#currentPage").val();
        var last = $("#totalPage").val();
        var page = Math.ceil((parseInt(num)) / 10);
        if (num < page * 10 && num != last) {
            //移除之前的active
            $(".pagination li a").removeClass("active");
            $("#" + (parseInt(num) + 1) + "").attr("class", "active");
            getTheTable(deparentNum, Number($(".active").html()))
            //$(".pagination li a[text="+(parseInt(num)+1)+"]").attr("class","active");//jQ1.6支持
            $("#currentPage").val(parseInt(num) + 1);
        } else if (num == page * 10 && num != last) {
            //清空之前的数据
            $(".pagination").html("");
            draw(page + 1, (parseInt(num) + 1));
        }
    })
    //绑定上一页点击事件
    $(document).off("click", "#previousPage");
    $(document).on("click", "#previousPage", function () {
        var num = $(".active").html();
        var curPage = $("#currentPage").val();
        var last = $("#totalPage").val();
        var page = Math.ceil((parseInt(num)) / 10);
        if (num <= page * 10 && num != (page - 1) * 10 + 1) {
            //移除之前的active
            $(".pagination li a").removeClass("active");
            $("#" + (parseInt(num) - 1) + "").attr("class", "active");
            getTheTable(deparentNum, Number($(".active").html()));
            //$(".pagination li a[text="+(parseInt(num)+1)+"]").attr("class","active");//jQ1.6支持
            $("#currentPage").val(parseInt(num) - 1);
        } else if (num == (page - 1) * 10 + 1 && num != 1) {
            //清空之前的数据
            $(".pagination").html("");
            draw(page - 1, (parseInt(num) - 1));
        }
    })

    //绘制页面分页样式
    function draw(page, curPage) {
        $(".pagination").empty();
        //页面中的当前页
        var page = page;
        //后台传过来的页数
        var curPage = curPage;
        //后台传过来的总页数
        var datas = $("#totalPage").val();
        //每页显示多少条数据
        var pageSize = 10;
        //在网页中一共要分多少页
        var totalPage = Math.floor((datas - 1) / pageSize + 1);

        var liStr = "<li><a id='previousPage' href='javascript:;'>«</a></li>";
        $("#currentPage").val(curPage);
        if (page <= totalPage) {
            if (datas <= 10) {
                for (i = 1; i <= datas; i++) {
                    //为当前页增加样式
                    var active = "";
                    if (i == curPage) {
                        active = " class='active' ";
                    }
                    liStr += " <li><a id=" + i + " " + active + " href='javascript:;'>" + i + "</a></li>"
                }
            } else {
                var start = pageSize * (page - 1) + 1;
                var end = page * pageSize;
                if (page == totalPage) {
                    for (i = start; i <= datas; i++) {
                        //为当前页增加样式
                        var active = "";
                        if (i == curPage) {
                            active = " class='active' ";
                        }
                        liStr += " <li><a id=" + i + " " + active + " href='javascript:;'>" + i + "</a></li>"
                    }
                } else {
                    for (i = start; i <= end; i++) {
                        //为当前页增加样式
                        var active = "";
                        if (i == curPage) {
                            active = " class='active' ";
                        }
                        liStr += " <li><a id=" + i + " " + active + " href='javascript:;'>" + i + "</a></li>"
                    }
                }
            }
        }
        liStr += "<li><a id='nextPage' href='javascript:;'>»</a></li>";
        $(".pagination").append(liStr);
    }
}

// 分页end

//编辑表begin
function editortable(arg) {
    var tableName = $(arg).parent().children().eq(6).text();
    var grade = $(arg).parent().children().eq(7).text();
    tableName += "," + grade;
    tableName = encodeURI(encodeURI(tableName));
    console.log("tableName", tableName)
    var url = "http://localhost:3000/editortable?tableName=" + tableName
    window.open(url);
}

// 查看表begin
function viewtable(arg) {
    var tableName = $(arg).parent().children().eq(6).text();
    var grade = $(arg).parent().children().eq(7).text();
    tableName += "," + grade;
    tableName = encodeURI(encodeURI(tableName));
    console.log("tableName", tableName)
    var url = "http://localhost:3000/viewtable?tableName=" + tableName
    window.open(url);
}

// 解锁3级巴被锁定的表
function unlockauthority(arg) {
    var tableName = $(arg).parent().children().eq(6).text();
    var departmentNum = $("tbody tr:eq(0) td:eq(1)").text();
    var grade = $(arg).parent().children().eq(7).text();
    var objdata = {tableName: tableName, grade: grade}
    $.ajax({
        async: true,
        type: "POST",
        data: objdata,
        url: "/unlockauthority"
    }).done(function (result) {
        alert(result.success);
        if (result.success.indexOf("解锁成功") != -1) {
            getTheTable(departmentNum);
        }

    })
}

function heckdata(props) {
    var tableName = $(props).parent().children().eq(6).text();
    var grade = $(props).parent().children().eq(7).text();
    if (grade != 3) {
        alert(grade + "级巴不能进行检验,只有3级巴才能检验")
    } else {
        window.open("http://amiba.ddbb.jpl56.com/checkpage?tableName=" + tableName)
    }

}

//下载begin
function download(arg) {
    var year = $(arg).parent().children("td").eq(2).text();
    var month = $(arg).parent().children("td").eq(3).text();
    var departmentNum = $("tbody tr:eq(0) td:eq(1)").text();
    var tableName = $("tbody tr:eq(0) td:eq(6)").text().split("_")[0];
    var grade = $("tbody tr:eq(0) td:eq(7)").text();
    var strHuiZhong = '金石报表系统/阿米巴/' + grade + '级巴/' + tableName;
    console.log(strHuiZhong);
    console.log("month", month);
    var dataDep = {"tableName": tableName, "year": year, "month": month, "grade": grade};
    var str3 = "http://amiba.ddbb.jpl56.com:8080/gFilke/out/" + tableName + "_" + year + "_" + month + ".xlsx?aa=" + parseInt(10000 * Math.random());

    window.open(str3);
    // $.ajax({
    //     async: false,
    //     type: "POST",
    //     url: "/download",
    //     data: dataDep,
    //     success: function (data) {
    //         console.log(data);
    //         var str3 = "http://amiba.ddbb.jpl56.com:8080/gFilke/out/" + tableName + "_" + year + "_" + month + ".xlsx";
    //         window.open(str3);
    //     }
    // })
}

//删除文件begin
function devaretable(arg) {
    var departmentNum = $("tbody tr:eq(0) td:eq(1)").text();//部门编号
    var year = $(arg).parent().children("td").eq(2).text();
    var month = $(arg).parent().children("td").eq(3).text();
    var departmentNum = $("tbody tr:eq(0) td:eq(1)").text();
    var tableName = $("tbody tr:eq(0) td:eq(6)").text().split("_")[0];
    var grade = $("tbody tr:eq(0) td:eq(7)").text();
    var strHuiZhong = '金石报表系统/阿米巴/' + grade + '级巴/' + tableName;
    console.log(strHuiZhong);
    console.log("month", month);
    var dataDep = {"tableName": tableName, "year": year, "month": month, "grade": grade};
    console.log("dataDep", dataDep);
    var r = confirm("请确认是删除该表？");
    if (r) {
        $.ajax({
            async: false,
            type: "POST",
            url: "/deleteform",
            data: dataDep,
            success: function (data) {
                if (data.success) {
                    getTheTable(departmentNum)
                }
            }
        })

    }
}

//上传文件
function uploadingFiles(obj) {

    var uploadForm = '<div id="uploadForm"><div class="uploadFormTitle">文件上传</div><form id="form1" action="upload/xgFilke" target="frame1" method="post" enctype="multipart/form-data"> <input type="file" name="file" id="files"> </form> <div> <input type="button" class="uploadFormUplod" value="取消" onclick="Shadow(this)"> <input type="button" class="uploadFormUplod" value="上传" onclick="upload(this)"> </div> <iframe name="frame1" frameborder="0" height="40" style="display: none;"></iframe> </div>';
    // $("body").remove(form);
    if ($("#uploadForm")) {
        $("#uploadForm").remove();
    }
    $("body").append(uploadForm);
    $(".uploadFormTitle").eq(0).css({
        "width": "100%",
        "height": "40px",
        "background": "#4e8a9e",
        "margin-bottom": "20px",
        "line-height": "40px",
        "text-indent": "10px"

    })
    $("#uploadForm").css({
        "position": "absolute",
        "left": "50%",
        "top": "50%",
        "transform": "translate(-50%,-50%)",
        "width": "286px",
        "height": "278px",
        "background": "#ffffff",
        "border": "2px solid #4e8a9e"
    })
    $(".uploadFormUplod").eq(0).css({
        "position": "absolute",
        "bottom": "20px",
        "left": "10px",
        "width": "120px",
        "height": "45px",
        "border": "1px solid red",
        "border-radius": "5px",
        "background": "#ff404a",
        "color": "#ffffff",
    })
    $(".uploadFormUplod").eq(1).css({
        "position": "absolute",
        "bottom": "20px",
        "right": "10px",
        "width": "120px",
        "height": "45px",
        "border": "1px solid red",
        "border-radius": "5px",
        "background": "#ffffff",

    })
    $("#files").css({
        "margin-left": "10px",
        "margin-top": "50px"
    })
}

//上传文件的状态
function upload(obj1) {
    if (document.getElementById("files").value == "") {
        alert("请选择上传的文件");
    } else {
        var form = new FormData(document.getElementById("form1"));
        $.ajax({
            async: true,
            url: "/upload/xgFilke",
            type: "post",
            data: form,
            processData: false,
            contentType: false
        }).done(function (result) {
            alert(result.success)
        })
        $("#uploadForm").css("display", "none")

    }

}

//取消上传
function Shadow() {
    $("#uploadForm").css("display", "none")
}

//查看表end
//是否可以新建抓取功能begin
(function () {
    var grade = $("tbody tr:eq(1) td:eq(8)").text();
    if (grade === "3") {
        $(".ui_input_btn02:eq(1)").toggleClass("ui_input_btn01");
    } else {
        $(".ui_input_btn02:eq(2)").toggleClass("ui_input_btn01");

    }
})()

//汇总报表begin
function summary(arg) {
    if ($(arg).hasClass("ui_input_btn01")) {
        $(".summary_box").eq(0).css({
            "display": "block"
        })
    }
}

//新建报表begin
function newlybuild(arg) {
    if ($(arg).hasClass("ui_input_btn01")) {
        $(".summary_box").eq(1).css({
            "display": "block"
        })
    }
}

// document.getElementsByClassName('datePicker')[0].valueAsDate = new Date();
// document.getElementsByClassName('datePicker')[1].valueAsDate = new Date();

function quxiao() {
    $(".summary_box").css({
        "display": "none"
    })
}

//确认汇总功能
function uploadSummary(obj) {
    if (obj != null) {
        var year = $("#year").val();
        var month = $("#month").val();
        var departmentNum = $("tbody tr:eq(0) td:eq(1)").text();
        var tableName = $("tbody tr:eq(0) td:eq(6)").text().split("_")[0];
        var grade = $("tbody tr:eq(0) td:eq(7)").text();
        var strHuiZhong = '金石报表系统/阿米巴/' + grade + '级巴/' + tableName;
        var str3 = "/jusudep?uploadSummary=" + encodeURI(strHuiZhong) + "/" + year + "." + month;
        var dbstr3 = {
            "tableName": tableName,
            "year": year,
            "month": month,
            "grade": grade,
            "departmentNum": departmentNum
        };
        $('.summary_box').hide();
        var r = confirm("请确认是否汇总？");
        if (r) {
            $.ajax({
                async: true,
                url: str3,
            }).done(function (data222) {
                if (data222.success) {
                    alert(data222.success);
                } else {
                    //服务器进行汇总begin
                    $.ajax({
                        type: "POST",
                        async: true,
                        url: "/uploadSummary",
                        data: JSON.stringify(dbstr3),
                    }).done(function (data333) {
                        getTheTable(departmentNum);

                        console.log("data333", data333);
                        var dataCal = {
                            "end": true,
                            "tablename": tableName,
                            "year": year, "month": month
                        };
                        if (data333.success) {
                            $.ajax({
                                type: "POST",
                                async: true,
                                url: "/allnonjump/Summary1",
                                data: dataCal,
                            }).done(function (data) {
                                console.log("在服务器上汇总成功", data);

                                //告诉客户机几秒钟后开始下载begin
                                $.ajax({
                                    async: true,
                                    url: "http://amiba.ddbb.jpl56.com:2222/uploadSummary?uploadSummary=" + encodeURI(strHuiZhong) + "/" + year + "." + month,
                                }).done(function (data) {
                                    console.log('在客户机上执行下载命令成功', data)
                                })
                                //告诉客户机几秒钟后开始下载end
                            })
                        }
                    })
                    //服务器进行汇总end
                }
            });
        }
    }
}

//确认单个抓取功能
function yMsubmit(obj) {
    if (obj != null) {
        var year = $("#yearHuiZong").val();
        var month = $("#monthHuiZong").val();
        var departmentNum = $("tbody tr:eq(0) td:eq(1)").text();
        var tableName = $("tbody tr:eq(0) td:eq(6)").text().split("_")[0];
        var grade = $("tbody tr:eq(0) td:eq(7)").text();
        var str2 = '金石报表系统/阿米巴/' + grade + '级巴/' + tableName;
        if (year == "" || month == "") {
            alert("请输入要抓取的年份和月份");
        } else {
            var str3 = "http://amiba.ddbb.jpl56.com:2222/YeatMonth?mallallurl=" + encodeURI(str2) + "/" + year + "." + month;
            // var dbstr3 = "/YeatMonth?mallallurl=" + encodeURI(str2) + "/" + year + "." + month;
            var dbstr3 = {
                "tableName": tableName,
                "year": year,
                "month": month,
                "grade": grade,
                "departmentNum": departmentNum
            };
            $('.summary_box').hide();
            var r = confirm("请确认是否抓取？");
            if (r) {
                $.ajax({
                    async: false,
                    url: str3,
                }).done(function (data222) {
                    alert(data222)
                    if (data222.indexOf("未抓取") == -1) {
                        $.ajax({
                            type: "POST",
                            async: true,
                            url: "/YeatMonth",
                            data: JSON.stringify(dbstr3),
                        }).done(function (data333) {
                            getTheTable(departmentNum)
                            console.log(data333);
                        })
                    }
                });
            }
        }
    }
}

//展示队列begin
function showDuilie(obj) {
    if (obj) {
        $(".taskqueue").toggle()
        $('#jinshan1').css('display', 'block');
        $('#tongcheng1').css('display', 'none');
        var str3 = "http://amiba.ddbb.jpl56.com:2222/showDuilie?showDuilie=true";
        $.ajax({
            async: true,
            url: str3,
        }).done(function (data) {
            console.log(data)
            $("#jinshan1 table:eq(0) tbody").empty();
            for (var i = 0; i < data.length; i++) {
                $("#jinshan1 table:eq(0) tbody").append('<tr><td>' + data[i][0] + '</td><td>' + data[i][1] + '</td><td>' + data[i][2] + '</td><td>' + data[i][3] + '</td><td>' + data[i][4] + '</td><td>' + data[i][5] + '</td></tr>');
            }
        });
    }
}

//展示单个抓取队列begin
function showSingle(obj) {
    if (obj) {
        var str3 = "/showSingle";
        $.ajax({
            type: 'POST',
            async: true,
            url: str3,
        }).done(function (data) {
            data = data.success;
            console.log(data)
            $("#tongcheng1 table:eq(0) tbody").empty();
            for (var i = 0; i < data.length; i++) {
                $("#tongcheng1 table:eq(0) tbody").append('<tr><td>' + data[i][0] + '</td><td>' + data[i][1] + '</td><td>' + data[i][2] + '</td><td>' + data[i][3] + '</td><td>' + data[i][4] + '</td><td>' + data[i][5] + '</td><td>' + data[i][6] + '</td><td>' + data[i][7] + '</td></tr>');
            }
        });
    }
}

//展示客户机的选项卡效果
$('#jinshan').bind("click", function () {
    $('#jinshan1').css('display', 'block');
    $('#tongcheng1').css('display', 'none');
})
$('#tongcheng').bind('click', function () {
    $('#jinshan1').css('display', 'none');
    $('#tongcheng1').css('display', 'block');
})

$('.posti').bind("click", function () {
    $(".taskqueue").css({
        "display": "none"
    })
})
